import pymysql
# 修改数据
try:
    con = pymysql.connect(host="localhost", user="root", password="rootroot", db="blog")
    print(con)
    cursor = con.cursor()

    # 将sno=5的学生成绩修改为99.5
    sql = 'update student set score=%s where sno=%s'

    # 执行sql
    cursor.execute(sql, (99.5, 5))
    # 获取查询结果
    con.commit()

    print("更新成功")
except Exception as e:
    print(e)
    con.rollback()
    print("更新失败")
finally:
    # 关闭数据库连接
    con.close()
